package com.finance.util.export;

import com.finance.base.exception.BaseException;

import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.util.List;


/**
 * Created by ljg on 2017/4/10.
 */
public class ExportFactory{

    private ExportBuilder builder;

    private int status=0;

    private ExportFactory() {
    }
    public static ExportFactory getExportFactory(ExportBuilder builder){
        ExportFactory exportFactory = new ExportFactory();
        exportFactory.builder = builder;
        exportFactory.builder.init();
        exportFactory.status = 0;
        return exportFactory;
    }

    public ExportFactory setDataList(List dataList){
        this.status = 1;
        builder.fillDataList(dataList);
        return this;
    }

    public ExportFactory setErrMsgList(List<String> errMsgList){
        builder.fillErrList(errMsgList);
        return this;
    }



    public void outPut(HttpServletResponse response){
        if(this.status != 1){
            throw new BaseException("没有数据");
        }
        builder.out(response);
    }
    public void outPut(File file){
        if(this.status != 1){
            throw new BaseException("没有数据");
        }
        builder.out(file);
    }

}